<template>
    <div class="template-form-Lu">
        <a-modal
            title="办公用品/设备领用"
            :visible="applicationFormVisible"
            :maskClosable="false"
            :closable="true"
            :destroyOnClose="true"
            width="100%"
            :dialog-style="{ margin: '0 auto' }"
            wrapClassName="applicationModal-form-fullmodal-Lu officeSupplies-div"
            @cancel="closeVisible">
            <div class="applicationModal-div-box-Lu">
                <div class="tabs-card-edit-box">
                    <a-tabs type="card" v-model:activeKey="summaryActiveKey" @change="summaryActiveChange">
                        <a-tab-pane key="申请表" tab="申请表"></a-tab-pane>
                        <a-tab-pane key="流转记录" tab="流转记录"></a-tab-pane>
                    </a-tabs>
                </div>
                <div  class="tab-box-v1">
                    <div v-if="summaryActiveKey == '申请表'" style="margin: 0 auto;">
                        <a-spin :spinning="spinning">
                            <div v-if="linkName == '申请'" style="display: flex;width: 100%;height: calc(100vh - 255px);margin-top: 20px;">
                                <div style="width: 330px;" class="blocking-div">
                                    <h3 class="officeSupplies-table-title" style="background-color: #5ca3e5;">办公设备列表</h3>
                                    <a-input-search style="margin-bottom: 8px" placeholder="搜索" @change="onChange" />
                                    <div style="overflow-y: scroll;height: calc(100vh - 360px);">
                                        <a-tree
                                            :expanded-keys="expandedKeys"
                                            :auto-expand-parent="autoExpandParent"
                                            :tree-data="mlList"
                                            @expand="onExpand"
                                            @select="onSelect"
                                        >
                                        <template slot="title" slot-scope="{ title }">
                                            <span v-if="title.indexOf(searchValue) > -1">
                                                {{ title.substr(0, title.indexOf(searchValue)) }}
                                                <span style="color: #f50">{{ searchValue }}</span>
                                                {{ title.substr(title.indexOf(searchValue) + searchValue.length) }}
                                            </span>
                                            <span v-else>{{ title }}</span>
                                        </template>
                                        </a-tree>
                                    </div>
                                </div>
                                <div style="flex: 1;">
                                    <div style="display: flex;height: calc(100vh - 350px);">
                                        <div style="flex: 1;margin: 0px 15px;" class="blocking-div">
                                            <h3 class="officeSupplies-table-title" style="background-color: #1ab394;">办公设备已勾选列表</h3>
                                            <table class="officeSupplies-table" border="1" borderColor="#d9d9d9" cellspacing="0" style="width: calc(100%);border-color: #d9d9d9 !important;">
                                                <tr style="background: #dee5ed !important;">
                                                    <th>品名</th>
                                                    <th>数量</th>
                                                    <th>单位</th>
                                                    <th style="width: 80px !important;"></th>
                                                </tr>
                                                <tr v-for="(item,index) in goodsListSb" :key="index" v-if="goodsListSb.length" :style="{background:(index+1) % 2 == 0?'#f0f0f1 !important':''}">
                                                    <td>
                                                        <a-input v-model="item.fsqmc" @blur="updataGoodsList({fsqmc:item.fsqmc,id: item.id})" placeholder="请输入物品名称"></a-input>
                                                    </td>
                                                    <td>
                                                        <a-input-number v-model="item.fsqsl" @blur="updataGoodsList({fsqsl:item.fsqsl,id: item.id})" placeholder="请输入物品数量"></a-input-number>
                                                    </td>
                                                    <td>
                                                        <a-input v-model="item.fdw" @blur="updataGoodsList({fdw:item.fdw,id: item.id})" placeholder="请输入物品单位"></a-input>
                                                    </td>
                                                    <td>
                                                        <a-icon type="delete" style="color: red;font-size: 18px;" @click="delGoodsList({sqmxid: item.id})"/>
                                                    </td>
                                                </tr>
                                                <tr v-if="!goodsListSb.length">
                                                    <td colspan="4">暂无数据</td>
                                                </tr>
                                            </table>
                                        </div>
                                        <div style="flex: 1;" class="blocking-div">
                                            <h3 class="officeSupplies-table-title" style="background-color: #66c24f;">办公用品列表<span style="color: red;">（自行添加）</span></h3>
                                            <table class="officeSupplies-table" border="1" borderColor="#d9d9d9" cellspacing="0" style="width: calc(100%);border-color: #d9d9d9 !important;">
                                                <tr style="background: #dee5ed !important;">
                                                    <th>品名</th>
                                                    <th>数量</th>
                                                    <th>单位</th>
                                                    <th style="width: 80px !important;">
                                                        <a-icon type="plus-circle" style="color: #5ca3e5;font-size: 18px;" @click="addGoodsList()"/>
                                                    </th>
                                                </tr>
                                                <tr v-for="(item,index) in goodsListYp" :key="index" v-if="goodsListYp.length" :style="{background:(index+1) % 2 == 0?'#f0f0f1 !important':''}">
                                                    <td>
                                                        <a-input v-model="item.fsqmc" @blur="updataGoodsList({fsqmc:item.fsqmc,id: item.id})" placeholder="请输入物品名称"></a-input>
                                                    </td>
                                                    <td>
                                                        <a-input-number v-model="item.fsqsl" @blur="updataGoodsList({fsqsl:item.fsqsl,id: item.id})" placeholder="请输入物品数量"></a-input-number>
                                                    </td>
                                                    <td>
                                                        <a-input v-model="item.fdw" @blur="updataGoodsList({fdw:item.fdw,id: item.id})" placeholder="请输入物品单位"></a-input>
                                                    </td>
                                                    <td>
                                                        <a-icon type="delete" style="color: red;font-size: 18px;" @click="delGoodsList({sqmxid: item.id})"/>
                                                    </td>
                                                </tr>
                                                <tr v-if="!goodsListYp.length">
                                                    <td colspan="4">暂无数据</td>
                                                </tr>
                                            </table>
                                        </div>
                                    </div>
                                    <div>
                                        <a-form :form="form" ref="form" class="internalControl-reimbursement-model-form-box">
                                            <a-descriptions bordered style="width: 100%;">
                                                <a-descriptions-item :span="3">
                                                    <span slot="label" class="descriptions-label-slot">
                                                        备&emsp;&emsp;注
                                                    </span>
                                                    <a-form-item ref="fbz" prop="fbz" class="zm-form-model">
                                                        <a-textarea
                                                            v-model="formState.fbz"
                                                            placeholder="请输入备注:"
                                                            :auto-size="{ minRows: 2}"
                                                        />
                                                    </a-form-item>
                                                </a-descriptions-item>
                                            </a-descriptions>
                                        </a-form>
                                    </div>
                                </div>
                            </div>
                            <div v-else style="flex: 1;width: 70%;height: 100%;">
                                <a-form :form="form" ref="form" class="internalControl-reimbursement-model-form-box">
                                    <a-descriptions bordered style="width: 100%;">
                                        <a-descriptions-item :span="3" v-if="linkName !== '申请'">
                                            <span slot="label" class="descriptions-label-slot">
                                                申请信息
                                            </span>
                                            <a-form-item ref="fbz" prop="fbz" class="zm-form-model">
                                                <span v-if="goodsListSb.length || goodsListYp.length">
                                                    办公设备：
                                                    <span v-for="(item,index) in goodsListSb">
                                                        {{ item.fsqmc + ' : ' + item.fsqsl + ' ( ' + item.fdw + ' ) ； ' }}
                                                    </span>
                                                    <span v-if="goodsListSb.length == 0">无</span>；
                                                    &ensp;
                                                    办公用品：
                                                    <span v-for="(item,index) in goodsListYp">
                                                        {{ item.fsqmc + ' : ' + item.fsqsl + ' ( ' + item.fdw + ' ) ； ' }}
                                                    </span>
                                                    <span v-if="goodsListYp.length == 0">无</span>；
                                                </span>
                                                <span v-if="goodsListSb.length == 0 && goodsListYp.length == 0">无匹配数据，备注填写。</span>
                                            </a-form-item>
                                        </a-descriptions-item>
                                        <a-descriptions-item :span="3">
                                            <span slot="label" class="descriptions-label-slot">
                                                备&emsp;&emsp;注
                                            </span>
                                            <a-form-item ref="fbz" prop="fbz" class="zm-form-model">
                                                <a-textarea
                                                    v-if="linkName=='申请' || linkName == '数据修订'"
                                                    v-model="formState.fbz"
                                                    placeholder="请输入备注:"
                                                    :auto-size="{ minRows: 2}"
                                                />
                                                <span v-else>{{ formState.fbz?formState.fbz:'无' }}</span>
                                            </a-form-item>
                                        </a-descriptions-item>
                                        <a-descriptions-item :span="3" v-if="descriptionsData('科室审批').hjmc">
                                            <span slot="label" class="descriptions-label-slot">
                                                <span class="xhText" v-if="linkName == descriptionsData('科室审批').hjmc">*</span>
                                                科室审批意见
                                            </span>
                                            <a-form-item ref="fksyj" prop="fksyj" class="zm-form-model">
                                                <div style="width: 100%;" v-if="(descriptionsData('科室审批').blzt == '待办' && linkName!=='我的已办') || linkName == '数据修订'">
                                                    <reviewOpinions
                                                        ref="reviewOpinionsReffksyj"
                                                        @getInputOpinion="getInputOpinion"
                                                        @openOpinions="opinions('办公用品',formState.fksyj,'fksyj')"
                                                        v-decorator="[
                                                            'fksyj', { initialValue:formState.fksyj, rules: rules.fksyj}
                                                    ]"/>
                                                    <div  v-if="linkName == '数据修订'" style="text-align: right;">
                                                        <span>办理时间：</span>
                                                        <a-date-picker
                                                            show-time
                                                            :v-model="moment(formState.fksyjsj)"
                                                            :default-value="moment(formState.fksyjsj)"
                                                            :allowClear="false"
                                                            @change="yjTimeChange($event,'fksyjsj')"
                                                        />
                                                    </div>
                                                </div>
                                                <div style="width: 100%;" v-else>
                                                    <p>{{ formState.fksyj }}</p>
                                                    <div class="yjqm-right-bottom">
                                                        <img v-if="getUrl('科室审批')" :src="getUrl('科室审批')" alt="" class="yjqmImg"/>
                                                        <span v-else class="yjqmImg">{{ formState.fksyjr }}</span>
                                                        <span>{{ formState.fksyjsj }}</span>
                                                    </div>
                                                </div>
                                            </a-form-item>
                                        </a-descriptions-item>
                                        <a-descriptions-item :span="3" v-if="descriptionsData('办公室确认').hjmc">
                                            <span slot="label" class="descriptions-label-slot">
                                                <span class="xhText" v-if="linkName == descriptionsData('办公室确认').hjmc">*</span>
                                                办公室确认
                                            </span>
                                            <a-form-item ref="fbgsyj" prop="fbgsyj" class="zm-form-model">
                                                <div style="width: 100%;" v-if="(descriptionsData('办公室确认').blzt == '待办' && linkName!=='我的已办') || linkName == '数据修订'">
                                                    <reviewOpinions
                                                        ref="reviewOpinionsReffbgsyj"
                                                        @getInputOpinion="getInputOpinion"
                                                        @openOpinions="opinions('办公用品',formState.fbgsyj,'fbgsyj')"
                                                        v-decorator="[
                                                            'fbgsyj', { initialValue:formState.fbgsyj, rules: rules.fbgsyj}
                                                    ]"/>
                                                    <div  v-if="linkName == '数据修订'" style="text-align: right;">
                                                        <span>办理时间：</span>
                                                        <a-date-picker
                                                            show-time
                                                            :v-model="moment(formState.fbgsyjsj)"
                                                            :default-value="moment(formState.fbgsyjsj)"
                                                            :allowClear="false"
                                                            @change="yjTimeChange($event,'fbgsyjsj')"
                                                        />
                                                    </div>
                                                </div>
                                                <div style="width: 100%;" v-else>
                                                    <p>{{ formState.fbgsyj }}</p>
                                                    <div class="yjqm-right-bottom">
                                                        <img v-if="getUrl('办公室确认')" :src="getUrl('办公室确认')" alt="" class="yjqmImg"/>
                                                        <span v-else class="yjqmImg">{{ formState.fbgsyjr }}</span>
                                                        <span>{{ formState.fbgsyjsj }}</span>
                                                    </div>
                                                </div>
                                            </a-form-item>
                                        </a-descriptions-item>
                                        <a-descriptions-item :span="3" v-if="descriptionsData('物品发放').hjmc">
                                            <span slot="label" class="descriptions-label-slot">
                                                <span class="xhText" v-if="linkName == descriptionsData('物品发放').hjmc">*</span>
                                                物品发放
                                            </span>
                                            <a-form-item ref="fwpffyj" prop="fwpffyj" class="zm-form-model">
                                                <div style="width: 100%;" v-if="(descriptionsData('物品发放').blzt == '待办' && linkName!=='我的已办') || linkName == '数据修订'">
                                                    <reviewOpinions
                                                        ref="reviewOpinionsReffwpffyj"
                                                        @getInputOpinion="getInputOpinion"
                                                        @openOpinions="opinions('办公用品',formState.fwpffyj,'fwpffyj')"
                                                        v-decorator="[
                                                            'fwpffyj', { initialValue:formState.fwpffyj, rules: rules.fwpffyj}
                                                    ]"/>
                                                    <div  v-if="linkName == '数据修订'" style="text-align: right;">
                                                        <span>办理时间：</span>
                                                        <a-date-picker
                                                            show-time
                                                            :v-model="moment(formState.fwpffyjsj)"
                                                            :default-value="moment(formState.fwpffyjsj)"
                                                            :allowClear="false"
                                                            @change="yjTimeChange($event,'fwpffyjsj')"
                                                        />
                                                    </div>
                                                </div>
                                                <div style="width: 100%;" v-else>
                                                    <p>{{ formState.fwpffyj }}</p>
                                                    <div class="yjqm-right-bottom">
                                                        <img v-if="getUrl('物品发放')" :src="getUrl('物品发放')" alt="" class="yjqmImg"/>
                                                        <span v-else class="yjqmImg">{{ formState.fwpffyjr }}</span>
                                                        <span>{{ formState.fwpffyjsj }}</span>
                                                    </div>
                                                </div>
                                            </a-form-item>
                                        </a-descriptions-item>
                                        <a-descriptions-item :span="3" v-if="descriptionsData('领用确认').hjmc">
                                            <span slot="label" class="descriptions-label-slot">
                                                <span class="xhText" v-if="linkName == descriptionsData('领用确认').hjmc">*</span>
                                                领用确认
                                            </span>
                                            <a-form-item ref="flyqryj" prop="flyqryj" class="zm-form-model">
                                                <div style="width: 100%;" v-if="(descriptionsData('领用确认').blzt == '待办' && linkName!=='我的已办') || linkName == '数据修订'">
                                                    <reviewOpinions
                                                        ref="reviewOpinionsRefflyqryj"
                                                        @getInputOpinion="getInputOpinion"
                                                        @openOpinions="opinions('办公用品',formState.flyqryj,'flyqryj')"
                                                        v-decorator="[
                                                            'flyqryj', { initialValue:formState.flyqryj, rules: rules.flyqryj}
                                                    ]"/>
                                                    <div  v-if="linkName == '数据修订'" style="text-align: right;">
                                                        <span>办理时间：</span>
                                                        <a-date-picker
                                                            show-time
                                                            :v-model="moment(formState.flyqryjsj)"
                                                            :default-value="moment(formState.flyqryjsj)"
                                                            :allowClear="false"
                                                            @change="yjTimeChange($event,'flyqryjsj')"
                                                        />
                                                    </div>
                                                </div>
                                                <div style="width: 100%;" v-else>
                                                    <p>{{ formState.flyqryj }}</p>
                                                    <div class="yjqm-right-bottom">
                                                        <img v-if="getUrl('领用确认')" :src="getUrl('领用确认')" alt="" class="yjqmImg"/>
                                                        <span v-else class="yjqmImg">{{ formState.flyqryjr }}</span>
                                                        <span>{{ formState.fksyjsj }}</span>
                                                    </div>
                                                </div>
                                            </a-form-item>
                                        </a-descriptions-item>
                                    </a-descriptions>
                                </a-form>
                            </div>
                        </a-spin>
                    </div>
                    <div v-if="summaryActiveKey == '流转记录'" style="padding-top: 30px;">
                        <transferRecords
                            ref="transferRecordsRef"
                            :config="circulationDataTableConfig"
                            @getCirculationQmImg="getCirculationQmImg"/>
                    </div>
                </div>
            </div>
            <template slot="footer">
                <div v-if="linkName =='我的已办'">
                    <a-button @click="closeVisible" class="blue-btn">关闭</a-button>
                </div>
                <div v-else-if="linkName == '数据修订'">
                    <a-button class="blue-btn" @click="updataData">确认修订</a-button>
                </div>
                <!-- <div v-else-if="linkName == '办公室确认'||linkName == '物品发放'||linkName == '领用确认'">
                    <a-button v-if="linkName == '物品发放'" class="blue-btn" @click="onSubmit">确认{{ linkName }}</a-button>
                    <a-button v-else class="blue-btn" @click="onSubmit">{{linkName}}</a-button>
                </div> -->
                <div v-else>
                    <a-button key="back" @click="onSave('保存')">
                        保存
                    </a-button>
                    <a-button class="blue-btn" @click="onSubmit('提交')">
                        提交
                    </a-button>
                    <a-button v-if="linkName !== '申请'" @click="returnClick" class="red-btn">退回</a-button>
                </div>
            </template>
        </a-modal>
    </div>
</template>
<script>
import {
    pidgetlchj,
    editFuntion,
    initBzFlow,
    saveFlow,
    submitFlow,
    returnUpperzdyFlowJob,
    officeSuppliesMlList,
    selectOaid,
    addsqmx,
    delsqmx,
    updatesqmx,
    getMoreUserSignLinkList,
} from './service/index'
import assessCheckApi from './service/api.js'
import transferRecords from '../modal/transferRecords'
// import printModal from '../modal/printModal'
import moment from 'moment'
export default {
    components: {
        transferRecords,
        // printModal,
    },
    data() {
        return {
            applicationFormVisible: false,
            summaryActiveKey: '申请表',
            spinning: false,
            form:this.$form.createForm(this, { name: 'form' }),
            formState: {},
            rules:{
                fsl: [{
                    required: true,
                    message: '请输入数量',
                    trigger: 'blur',
                }],
                frq: [{
                    type: 'object',
                    required: true,
                    message: '请选择日期',
                    trigger: 'blur',
                }],
                fksyj: [
                    { required: true, message: '请输入本科（室）意见', trigger: 'blur' }
                ],
                fbgsyj: [
                    { required: true, message: '请输入办公室意见', trigger: 'blur' }
                ],
                fwpffyj: [
                    { required: true, message: '请输入物品发放意见', trigger: 'blur' }
                ],
                flyqryj: [
                    { required: true, message: '请输入领用确认意见', trigger: 'blur' }
                ],
            },
            moment:moment,
            circulationDataTableConfig: {
                api: assessCheckApi.flowJkPage,
                rowId: 'id',
                urlType: true,
                paramet:{
                    oaid: ''
                }
            },
            linkName: '申请',
            qmImgList: [],
            displayList: [],
            goodsList: [],
            goodsListSb: [],
            goodsListYp: [],
            mlList: [],
            expandedKeys: [],
            searchValue: '',
            autoExpandParent: true,
            gData:[],
        }
    },
    methods: {
        getInitData(){
            this.formState = {}
            this.goodsListSb = []
            this.goodsListYp = []
            this.getMlList()
            this.onSave()
        },
        getData(val){
            if(val){
                this.linkName = val.hjmc
                this.formState = {}
                this.formState = {
                    ...val.oaMap,
                    jobid: val.jobMap?val.jobMap.id:''
                }
                this.goodsList = []
                this.goodsListSb = []
                this.goodsListYp = []
                this.goodsList = val.mxList?val.mxList:[]
                this.goodsList.forEach(item => {
                    if(item.flx == '办公用品'){
                        this.goodsListYp.push(item)
                    } else if(item.flx == '办公设备') {
                        this.goodsListSb.push(item)
                    }
                })
                this.circulationDataTableConfig.paramet.oaid = this.formState.id
                this.getMlList()
                this.getDisplayList()
            }
        },
        getDisplayList(){
            pidgetlchj({pid:this.formState.id}).then((res) => {
                let arr1 = res.result
                this.displayList = []
                this.displayList = res.result

                if(this.linkName == '数据修订'){
                    const index = this.displayList.findIndex((item) => item.blzt == '待办');
                    if (index !== -1) {
                        this.displayList.splice(index, 1);
                    }
                    //console.log('this.displayList',this.displayList)
                }

                arr1.forEach(async item => {
                    if(item.blrid && item.blzt!=='待办'){
                        let resa = await getMoreUserSignLinkList({ids:item.blrid})
                        if(resa.success && resa.result.length){
                            if(resa.result[0].signLink == ''){
                                // //console.log('没有获得图片 signLink == 0')
                                this.qmImgList.push({
                                    hjmc: item.hjmc,
                                    url: null
                                })
                            } else {
                                this.qmImgList.push({
                                    hjmc: item.hjmc,
                                    url: resa.result[0].signLink+'&aa='+Date.now()
                                })
                                // //console.log('获得的签名图片列表',this.qmImgList)
                            }
                        } else {
                            // //console.log('没有获得图片')
                        }
                    } else {}
                })
                // //console.log('最终获得的签名图片列表---',this.qmImgList)
            })
        },
        getMlList(){
            this.mlList = []
            officeSuppliesMlList().then(res => {
                if(res.success){
                    // this.mlList = res.result.records
                    let array = JSON.parse(JSON.stringify(res.result.records).replace(/fpm/g,"title").replace(/id/g,"key"))
                    this.mlList = array

                    addScopedSlots(this.mlList)
                    function addScopedSlots(obj) {
                        for (var i in obj) {
                            obj[i] = {
                                ...obj[i],
                                scopedSlots: { title: 'title' },
                            }
                            if(obj[i].children.length > 0){
                                addScopedSlots(obj[i].children)
                            }
                        }
                    }
                    this.generateList(this.mlList)
                }
            })
        },
        generateList(data){
            for (let i = 0; i < data.length; i++) {
                const node = data[i];
                const key = node.key;
                this.gData.push({ key, title: node.title });
                if (node.children) {
                    this.generateList(node.children);
                }
            }
        },
        // 展开/收起节点时触发
        onExpand(expandedKeys) {
            this.expandedKeys = expandedKeys;
            this.autoExpandParent = false;
        },
        // 点击节点时触发
        onSelect(selectedKeys, info) {
            //console.log('onSelect', info.node._props.dataRef);
            let item = {}
            item = {...info.node._props.dataRef}
            if(item.children.length == 0){
                this.addGoodsList(item)
            }
        },
        onChange(e) {
            const value = e.target.value;
            const expandedKeys = this.gData
                .map(item => {
                    if (item.title.indexOf(value) > -1) {
                        return this.getParentKey(item.key, this.mlList);
                    }
                    return null;
                })
                .filter((item, i, self) => item && self.indexOf(item) === i);
            Object.assign(this, {
                expandedKeys,
                searchValue: value,
                autoExpandParent: true,
            });
        },
        getParentKey(key, tree){
            let parentKey;
            for (let i = 0; i < tree.length; i++) {
                const node = tree[i];
                if (node.children) {
                if (node.children.some(item => item.key === key)) {
                    parentKey = node.key;
                } else if (this.getParentKey(key, node.children)) {
                    parentKey = this.getParentKey(key, node.children);
                }
                }
            }
            return parentKey;
        },
        summaryActiveChange(val){},
        getCirculationQmImg(item1,item2){
            //console.log('-----?????-----',item1,item2)
        },
        getUrl(hjmcName){
            let url = ''
            // //console.log('没有？？？',this.qmImgList)
            this.qmImgList.forEach(item => {
                //console.log(hjmcName,item)
                if(item.hjmc == hjmcName){
                    url = item.url
                }
            })
            // //console.log(hjmcName,url)
            return url
        },
        descriptionsData(hjmc){
            let data = {}
            this.displayList.forEach(item => {
                // //console.log('descriptionsData000',hjmc,item)
                if(item.hjmc == hjmc){
                    data = {...item}
                }
            })
            // //console.log('descriptionsData',data)
            return data
        },
        getInputOpinion(val,valueData){
            //console.log(val,valueData)
            let data = this.formState
            data[valueData.hjmc] = val
            this.form.setFieldsValue({
                fksyj: this.formState.fksyj,
                fbgsyj: this.formState.fbgsyj,
                ffgldyj: this.formState.ffgldyj,
                fzxld: this.formState.fzxld
            });
        },
        opinions(val1,val2,val3){
            //console.log(val1,val2,val3)
            this.$refs[`reviewOpinionsRef${val3}`].getData({opinionType:val1,oldVal:val2,valueData:{hjmc:val3}})
        },
        closeVisible(){
            this.applicationFormVisible = false
            this.$emit('success')
        },
        getGoodsList(){
            this.goodsListSb = []
            this.goodsListYp = []
            selectOaid({oaid:this.formState.id}).then(res => {
                if(res.success){
                    // this.goodsList = res.result
                    let result = res.result
                    result.forEach(item => {
                        if(item.flx == '办公用品'){
                            this.goodsListYp.push(item)
                        } else if(item.flx == '办公设备') {
                            this.goodsListSb.push(item)
                        }
                    })
                }
            })
        },
        addGoodsList(item){
            let data = {}
            if(item){
                data = {
                    fsqmc: item.title,
                    fsqid: this.formState.id,
                    fsqsl: 1,
                    fsjsqsl: 1,
                    flx: '办公设备',
                }
            } else {
                data = {
                    fsqmc: null,
                    fsqid: this.formState.id,
                    fsqsl: 1,
                    fsjsqsl: 1,
                    flx: '办公用品',
                }
            }
            //console.log('22222222',this.formState)
            addsqmx(data).then(res => {
                if(res.success){
                    this.$message.success(res.message)
                    this.getGoodsList()
                }
            })
        },
        delGoodsList(item){
            var that = this
            that.$confirm({
                title: '您确定要删除吗?',
                onOk() {
                    delsqmx({...item}).then(res => {
                        if(res.success){
                            that.getGoodsList()
                            that.$message.success(res.message)
                        }
                    })
                }
            })
        },
        updataGoodsList(item){
            updatesqmx({...item}).then(res => {
                if(res.success){
                    this.$message.success(res.message)
                } else {
                    this.$message.warning(res.message)
                }
                this.getGoodsList()
            })
        },
        onSave(){
            let data = {}
            let sdata = {
                jobid: this.formState.jobid,
                oaid: this.formState.id,
                map: {},
                opinion: '',
            }
            if(this.linkName == '申请'){
                data = {
                    fbz: this.formState.fbz,
                    id: this.formState.id?this.formState.id:''
                }
                sdata.map = {
                    ...data
                }
                this.formState.id?this.saveFlowFuntion(sdata):this.initBzFlowFuntion(data)
            } else if(this.linkName == '科室审批'){
                sdata.map = {
                    fksyj: this.formState.fksyj,
                    fksyjr: this.formState.fksyjr,
                    fksyjsj: this.formState.fksyjsj
                }
                sdata.opinion = this.formState.fksyj,
                this.saveFlowFuntion(sdata)
            } else if(this.linkName == '办公室确认'){
                sdata.map = {
                    fbgsyj: this.formState.fbgsyj,
                    fbgsyjr: this.formState.fbgsyjr,
                    fbgsyjsj: this.formState.fbgsyjsj
                }
                sdata.opinion = this.formState.fbgsyj,
                this.saveFlowFuntion(sdata)
            } else if(this.linkName == '物品发放'){
                sdata.map = {
                    fwpffyj: this.formState.fwpffyj,
                    fwpffyjr: this.formState.fwpffyjr,
                    fwpffyjsj: this.formState.fwpffyjsj
                }
                sdata.opinion = this.formState.fwpffyj,
                this.saveFlowFuntion(sdata)
            } else if(this.linkName == '领用确认'){
                sdata.map = {
                    flyqryj: this.formState.flyqryj,
                    flyqryjr: this.formState.flyqryjr,
                    flyqryjsj: this.formState.flyqryjsj,
                }
                sdata.opinion = this.formState.flyqryj,
                this.saveFlowFuntion(sdata)
            }
        },
        onSubmit(){
            this.form.validateFields((err, values) => {
                if (!err) {
                    var that = this
                    that.$confirm({
                        title: '您确定要提交吗?',
                        onOk() {
                            let data = {
                                jobid: that.formState.jobid,
                                oaid: that.formState.id,
                                map: {},
                                opinion: '',
                            }
                            if(that.linkName == '申请'){
                                data.map = {
                                    fbz: that.formState.fbz,
                                    id: that.formState.id?that.formState.id:'',
                                    fsffqlc: that.formState.id?'':'是',
                                }
                                that.formState.id?that.submitFlowFuntion(data):that.initBzFlowFuntion(data.map,'1')
                            } else if(that.linkName == '科室审批'){
                                data.map = {
                                    fksyj: that.formState.fksyj,
                                    fksyjr: that.formState.fksyjr,
                                    fksyjsj: that.formState.fksyjsj
                                }
                                data.opinion = that.formState.fksyj,
                                that.submitFlowFuntion(data)
                            } else if(that.linkName == '办公室确认'){
                                data.map = {
                                    fbgsyj: that.formState.fbgsyj,
                                    fbgsyjr: that.formState.fbgsyjr,
                                    fbgsyjsj: that.formState.fbgsyjsj
                                }
                                data.opinion = that.formState.fbgsyj,
                                that.submitFlowFuntion(data)
                            } else if(that.linkName == '物品发放'){
                                data.map = {
                                    fwpffyj: that.formState.fwpffyj,
                                    fwpffyjr: that.formState.fwpffyjr,
                                    fwpffyjsj: that.formState.fwpffyjsj
                                }
                                data.opinion = that.formState.fwpffyj,
                                that.submitFlowFuntion(data)
                            } else if(that.linkName == '领用确认'){
                                data.map = {
                                    flyqryj: that.formState.flyqryj,
                                    flyqryjr: that.formState.flyqryjr,
                                    flyqryjsj: that.formState.flyqryjsj,
                                }
                                data.opinion = that.formState.flyqryj,
                                that.submitFlowFuntion(data)
                            }
                        },
                        onCancel() {},
                    });
                }
            })
        },
        initBzFlowFuntion(data,type){
            initBzFlow(data).then(res => {
                if(res.code == 200){
                    this.$message.success(res.message)
                    this.formState = {}
                    this.formState = {
                        ...res.result.oaMap,
                        jobid: res.result.jobMap.id
                    }
                    //console.log('11111',this.formState)
                    this.getGoodsList()
                    if(type){
                        this.closeVisible()
                    }
                } else {
                    this.$message.warning(res.message)
                }
            })
        },
        saveFlowFuntion(data){
            this.spinning = true
            saveFlow(data).then(res => {
                if(res.code == 200){
                    this.$message.success(res.message)
                } else {
                    this.$message.warning(res.message)
                }
                this.spinning = false
            })
        },
        submitFlowFuntion(data){
            this.spinning = true
            submitFlow(data).then(res => {
                if(res.code == 200){
                    this.$message.success(res.message)
                    this.closeVisible()
                } else {
                    this.$message.warning(res.message)
                }
                this.spinning = false
            })
        },
        // 退回
        returnClick(){
            this.form.validateFields((err, values) => {
                if (!err) {
                    var that = this
                    that.$confirm({
                        title: '您确定要退回吗?',
                        onOk() {
                            that.spinning = true
                            queryJobByJobId({jobid:that.formState.jobid}).then(res => {
                                let list = res.result.jobHistoryList
                                let slist = list.filter(item => item.fhjmc == '起草')
                                const sortedDates = slist.sort((a, b) => new Date(b) - new Date(a));
                                that.returnFuntion(that.formState.jobid,sortedDates[slist.length - 1].id)
                            })
                        },
                        onCancel() {},
                    });
                }
            })
        },
        returnFuntion(jobid,ids){
            let returnStr = ''
            if(this.linkName == '科室审批'){
                returnStr = this.formState.fksyj
            } else if(this.linkName == '办公室确认'){
                returnStr = this.formState.fbgsyj
            } else if(this.linkName == '物品发放'){
                returnStr = this.formState.fwpffyj
            } else if(this.linkName == '领用确认'){
                returnStr = this.formState.flyqryj
            }
            let data = {
                jobid: jobid,
                opinion: returnStr,
                shjid: ids,
                lcmbbm: '',
                smgflag: '',
                smsContent: '',
            }
            returnUpperzdyFlowJob(data).then(res => {
                if(res.code == 200){
                    this.$message.success(res.message)
                    this.closeVisible()
                } else {
                    this.$message.error(res.message)
                }
                this.spinning = false
            })
        },
        updataData(){
            var that = this
            that.$confirm({
                title: '您确定修改当前表单数据吗?',
                onOk() {
                    let data = {
                        id: that.formState.id,

                        fksyj: this.formState.fksyj,
                        fksyjr: this.formState.fksyjr,
                        fksyjsj: this.formState.fksyjsj,
                        fbgsyj: this.formState.fbgsyj,
                        fbgsyjr: this.formState.fbgsyjr,
                        fbgsyjsj: this.formState.fbgsyjsj,
                        fwpffyj: this.formState.fwpffyj,
                        fwpffyjr: this.formState.fwpffyjr,
                        fwpffyjsj: this.formState.fwpffyjsj,
                        flyqryj: this.formState.flyqryj,
                        flyqryjr: this.formState.flyqryjr,
                        flyqryjsj: this.formState.flyqryjsj,
                    }
                    //console.log(data)
                    that.spinning = true
                    editFuntion(data).then(res => {
                        if(res.code == 200){
                            that.$message.success(res.message)
                        } else {
                            that.$message.warning(res.message)
                        }
                        that.spinning = false
                    })
                },
                onCancel() {
                    //console.log('Cancel');
                },
            });
        },
    },
}
</script>
<style>
@import url('../css/oaLess.css');
</style>
<style lang="less">
.officeSupplies-div {
    .blocking-div {
        border: 1px solid #e4e3e3;
        padding: 0px 15px 10px;
        border-radius: 5px;
    }
    .tab-box-v1 {
        padding: 0 20px;
    }
    .officeSupplies-table-title {
        text-align: center;
        font-family: '宋体' !important;
        font-weight: bold;
        margin-top: 0.5em;
        color: white;
        border: 1px solid #e4e3e3;
        border-radius: 50px;
        padding: 5px;
    }
    .officeSupplies-table{
        table-layout: fixed;
        th{
            text-align: center;
            font-size: 16px;
            padding: 3px 5px;
        }
        td{
            text-align: center;
            padding: 3px 5px;
            height: 40px;
            font-size: 16px;
        }
        .special-table-lable-td{
            background-color: #e6f7ff;
        }
    }
}
</style>
